/**
 /**
 * 初始化诊疗方案维护详情对话框
 */
var SdcTreatPlanInfoDlg = {
    treatPlanData: {},
    qCRuleCompare: "yes",
    qCRuleId: "",
    validateFields: {
        itemName: {
            validators: {
                notEmpty: {
                    message: '方案名称不能为空'
                }
            }
        }
    }
};



SdcTreatPlanInfoDlg.search = function () {
    SdcTreatPlanInfoDlg.initSourceForm();
};

SdcTreatPlanInfoDlg.clearData = function () {
    this.treatPlanData = {};
}

SdcTreatPlanInfoDlg.set = function (key, value) {
    this.treatPlanData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
    return this;
}

SdcTreatPlanInfoDlg.get = function (key) {
    return $("#" + key).val();
}

SdcTreatPlanInfoDlg.sourceChange = function (source) {
    var sourceId = source.value;
    $('#dataSourceItem').combobox("clear");
    //根据父级机构 查询子机构
    var ajax = new $ax(Sys.backendPath + "/sds/sdsqcformitem/getSourceFieldAndStandDic", function (res) {
        var fieldMap = $.parseJSON(res.fieldMap);
        $('#dataSourceItem').combobox({
            data: fieldMap,
            valueField: 'value',
            textField: 'text',
            onLoadSuccess: function () {
                $(this).combobox("setValue", "");
            }
        });
    }, function (data) {
        Sys.error("查询失败!" + data.responseJSON.message + "!");
    });
    ajax.set({"sourceId": sourceId});
    ajax.setAsync(false);
    ajax.start();
}

SdcTreatPlanInfoDlg.switchChange = function (event, obj) {
    if (obj.value) {
        $("#referenceFlag").show();
    } else {
        $("#referenceFlag").hide();
    }
}

SdcTreatPlanInfoDlg.switchChange2 = function (event, obj) {
    if (obj.value) {
        $("#referencePremiseFlag").show();
        $("#showPremiseFlag").show();
    } else {
        $("#referencePremiseFlag").hide();
        $("#showPremiseFlag").hide();
    }
}


SdcTreatPlanInfoDlg.collectData = function () {
    this.set('dataSource1', $('#dataSource1').combobox('getValue')).set('dataSourceItem1', $('#dataSourceItem1').combobox('getValue'))
        .set('dataSource2', $('#dataSource2').combobox('getValue')).set('dataSourceItem2', $('#dataSourceItem2').combobox('getValue'))
        .set('param1', encodeURIComponent($('#param1').val())).set('ruleMemo', $('#ruleMemo').val())
        .set('param2', encodeURIComponent($('#param2').val())).set('operator1', encodeURIComponent($('#operator1').val()))
        .set('operator2', encodeURIComponent($('#operator2').val()))
        .set('ruleDesc', $('#ruleDesc').val()).set('expCode', $("#expCode").val()).set('id', $("#id").val());
};


/**
 * 关闭此对话框
 */
SdcTreatPlanInfoDlg.close = function () {
    parent.layer.close(parent.layer.getFrameIndex(window.name)); //先得到当前iframe层的索引,再执行关闭
}

/**
 * 验证数据是否为空
 */
SdcTreatPlanInfoDlg.validate = function () {
    $('#sdcTreatPlanInfoForm').data("bootstrapValidator").resetForm();
    $('#sdcTreatPlanInfoForm').bootstrapValidator('validate');
    return $("#sdcTreatPlanInfoForm").data('bootstrapValidator').isValid();
}

/**
 * 提交新增
 */
SdcTreatPlanInfoDlg.addSubmit = function () {

    if (!this.validate()) {
        return;
    }
    var queryData = {};
    var ajax = new $ax(Sys.backendPath + "/sdc/sdctreatplan/updateTreatPlan", function (data) {
        //SdsDataConfig.initSourceForm();
        Sys.success("修改成功!");
        window.parent.SdcTreatPlan.table.refresh();
        SdcTreatPlanInfoDlg.close();
    }, function (data) {
        Sys.error("修改失败!" + data.responseJSON.message + "!");
    });
    //ajax.set(this.qcRuleData);
    queryData['id'] = $("#id").val();
    queryData['recommendType'] = $("#recommendType").val();
    queryData['itemName'] = Common_GetValue('itemName');
    queryData['itemDesc'] = Common_GetValue('itemDesc');
    queryData['qcentityId'] = Common_GetValue('qcEntity');
    queryData['sourceFlag'] = Common_GetValue('sourceFlag') ? 1 : 0;
    queryData['noCondition'] = Common_GetValue('noCondition') ? 1 : 0;
    queryData['qcId'] = Common_GetValue('qcId');
    queryData['type'] = Common_GetValue('vteType');
    queryData['isActive'] = Common_GetValue('isActive') ? 1 : 0;
    ajax.setData(queryData);
    ajax.start();
}

/**
 * 提交修改
 */
SdcTreatPlanInfoDlg.editSubmit = function () {

    if (!this.validate()) {
        return;
    }
    //提交信息
    Sys.ajaxForm('sdcTreatPlanInfoForm', Sys.backendPath + "/sdc/sdcqcconfig/updateRule", function (res) {
        Sys.success(res.message);
        window.parent.obj.qCChange();
        SdcQcRuleInfoDlg.close();
    });
}

function Common_GetValue() {
    var itmValue = '';

    if (typeof (arguments[0]) !== 'string') return '';
    if (arguments[0] == '') return '';

    var $this = $('#' + arguments[0]);
    if ($this.length < 1) return '';

    var className = $this.attr("class").split(' ')[0];

    if (className == 'textbox') {  //文本框
        itmValue = $this.val();
    } else if (className == 'hisui-numberbox') {  //数字
        itmValue = $this.val();
    } else if (className == 'hisui-datebox') {  //日期
        itmValue = $this.datebox('getValue');
    } else if (className == 'hisui-timespinner') {  //时间框
        itmValue = $this.timespinner('getValue');
    } else if (className == 'hisui-combobox') {  //下拉框（多选下拉框没有封装）
        itmValue = $this.combobox('getValue');
    } else if (className == 'hisui-switchbox') {  //开关
        itmValue = $this.switchbox('getValue');
    } else if (className == 'hisui-checkbox') {  // 单个复选框
        itmValue = $this.checkbox('getValue');
    } else if (className == 'hisui-radio') {  //单个单选框
        itmValue = $this.radio('getValue');
    } else if (className == 'hisui-searchbox') {  //查询框框
        itmValue = $this.searchbox('getValue');
    }

    return itmValue;
}

SdcTreatPlanInfoDlg.initSourceForm = function () {
    var params = {};
    params.id = $("#id").val();
    params.recommendType = $("#recommendType").val();
    var ajax = new $ax(Sys.backendPath + "/sdc/sdctreatplan/treatPlan", function (data) {

        $("#id").val(data.id);
        $("#qcEntity").combobox("select", data.qcentityId)
        $("#sourceFlag").checkbox('setValue', (data.sourceFlag) ? true : false);
        $("#noCondition").checkbox('setValue', (data.noCondition) ? true : false);
        $("#referenceEvent").switchbox('setValue', (data.dataSourceItem) ? true : false);
        $("#isActive").checkbox('setValue', (data.isActive) ? true : false);

        var ajax4 = new $ax(Sys.backendPath + "/sdc/sdcqccdsslink/selectByNodeId", function (data) {
            $("#qcId").combobox("select", data.qcItemId)
        }, function (data) {
            $("#qcId").combobox("select", "")
        });
        ajax4.set({"nodeId": data.nodeId});
        ajax4.start();
        $("#itemName").val(data.itemName);
        $("#itemDesc").val(data.itemDesc);
        $("#vteType").val(data.type);
    }, function (data) {
    });
    ajax.setData(params);
    ajax.start();

}


$(function () {
    Sys.initValidator("sdcTreatPlanInfoForm", SdcTreatPlanInfoDlg.validateFields);

    $HUI.combobox('#timeUnit',
        {
            data: [
                {'value': '1', 'Desc': "年"},
                {'value': '2', 'Desc': "月"},
                {'value': '3', 'Desc': "日"},
                {'value': '4', 'Desc': "时"},
                {'value': '5', 'Desc': "分"},
                {'value': '6', 'Desc': "秒"},
            ],
            valueField: 'value',
            textField: 'Desc',
        })

    $HUI.combobox('#qcEntity',
        {
            data: $.parseJSON($("#qcEntityMap").val()),
            valueField: 'value',
            textField: 'text',
            defaultFilter: 6
        })


    $HUI.combobox('#qcId',
        {
            data: $.parseJSON($("#qcMap").val()),
            valueField: 'value',
            textField: 'text',
            defaultFilter: 6
        })

    SdcTreatPlanInfoDlg.initSourceForm();
});
